package com.matt.repository.rel;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import com.matt.domain.rel.RelUserChildren;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/7/18
 * *******************************
 */
public interface RelUserChildrenRepository extends JpaRepository<RelUserChildren,String>{

    RelUserChildren findByUserIdAndChildrenIdAndRelation(String userId, String childrenId,String ralation);

    RelUserChildren findByChildrenIdAndRelation(String childrenId,String ralation);

    RelUserChildren findByChildrenIdAndUserIdAndId(String childrenId,String userId, String rid);

    @Modifying
    @Transactional
    @Query(value="delete from RelUserChildren c where c.childrenId = ?1 and c.userId = ?2")
    void  deleteByChildrenIdAndUserId(String childrenId, String userId);

    @Modifying
    @Transactional
    @Query(value="delete from RelUserChildren c where c.childrenId = ?1 ")
    void  deleteByChildrenId(String childrenId);

    @Modifying
    @Transactional
    @Query(value="update RelUserChildren c set c.relation = ?3,c.remark = ?4 where c.userId = ?1 and c.childrenId = ?2 ")
    void  updateByUidAndCid(String uid,String cid,String relation,String remark);
}
